import request from "@/utils/request";
import {
  DictForm,
  DictPageVO,
  DictQuery,
  DictTypeForm,
  DictTypePageVO,
  DictTypeQuery,
} from "./type";

/**
 * 字典类型分页列表
 *
 * @param queryParams
 */
export function getDictTypePageApi(
  queryParams: DictTypeQuery
): PageResult<DictTypePageVO> {
  return request({
    url: "/dict/types/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 字典类型表单数据
 *
 * @param id
 */
export function getDictTypeFormApi(id: number): Result<DictTypeForm> {
  return request({
    url: "/dict/types/" + id + "/form",
    method: "get",
  });
}

/**
 * 新增字典类型
 *
 * @param data
 */
export function addDictTypeApi(data: DictTypeForm): Result<void> {
  return request({
    url: "/dict/types",
    method: "post",
    data: data,
  });
}

/**
 * 修改字典类型
 *
 * @param id
 * @param data
 */
export function updateDictTypeApi(data: DictTypeForm): Result<void> {
  return request({
    url: "/dict/types",
    method: "put",
    data: data,
  });
}

/**
 * 删除字典类型
 */
export function deleteDictTypeApi(ids: string): Result<void> {
  return request({
    url: "/dict/types/" + ids,
    method: "delete",
  });
}

/**
 * 获取字典类型的数据项
 *
 * @param typeCode 字典类型编码
 */
export function getDictOptionsApi(typeCode: string): Result<SelectBox[]> {
  return request({
    url: "/dict/data/" + typeCode + "/options",
    method: "get",
  });
}

/**
 * 字典分页列表
 */
export function getDictPageApi(queryParams: DictQuery): PageResult<DictPageVO> {
  return request({
    url: "/dict/data/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取字典表单数据
 *
 * @param id
 */
export function getDictFormDataApi(id: number): Result<DictForm> {
  return request({
    url: "/dict/data/" + id + "/form",
    method: "get",
  });
}

/**
 * 新增字典
 *
 * @param data
 */
export function addDictApi(data: DictForm): Result<void> {
  return request({
    url: "/dict/data",
    method: "post",
    data: data,
  });
}

/**
 * 修改字典项
 *
 * @param data
 */
export function updateDictApi(data: DictForm): Result<void> {
  return request({
    url: "/dict/data",
    method: "put",
    data: data,
  });
}

/**
 * 删除字典
 *
 * @param ids 字典项ID，多个以英文逗号(,)分割
 */
export function deleteDictApi(ids: string): Result<void> {
  return request({
    url: "/dict/data/" + ids,
    method: "delete",
  });
}
